import { getStorage } from './storage';
import requestApi from './request';
//数据字典
const getDictionary = (key) => {
    // 从localStorage中获取字典
    const dictionary = getStorage(key);
    // 如果字典不存在，则返回空数组
    if (!dictionary) {
        return [];
    }
    // 如果字典存在，则返回字典
    return dictionary;
}
//数据字典接口实现
const getDictionaryReq = async (jsonData) => {
    let resData = await requestApi({
        url: jsonData.url,
        method: jsonData.method?jsonData.method:'post',
        data: jsonData.params,
    })
    if(jsonData.labelName&&jsonData.valueName){
        let resList = resData.data.map((item)=>{
            return {
                ...item,
                label:item[jsonData.labelName],
                value:item[jsonData.valueName]
            }
        })
        return resList;
    }else{
        return resData.data;
    }
}
export {
    getDictionary,
    getDictionaryReq
}